<?php
/**
 * Created by PhpStorm.
 * User: 24369
 * Date: 2021/6/26
 * Time: 9:44
 */
namespace app\admin\model;

use think\Model;
use think\model\concern\SoftDelete;

class User extends Model
{
    use SoftDelete;
    protected $deleteTime='delete_time';
    public function getSexAttr($v,$d){
        $sex=[
            0=>'女',
            1=>'男'
        ];
        return  $sex[$d['sex']];
    }
    public function searchKeywordsAttr($q,$v,$d){
        if (isset($v)&&$v!='')      $q->where('uname','like',"%{$v}%");
    }
    public static function getUserList($where,$keywords)
    {
        $list=User::field(true)
            ->withSearch(array_keys($where),$where)
            ->paginate([
                'list_rows'=>5,
            ])
            ->each(function ($item,$key) use ($keywords){
                $new_key="<span style='color: red;'>{$keywords}</span>";
                $item['uname']=str_replace($keywords,$new_key,$item['uname']);
            });
        return  $list;
    }
}